﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace INdT_Core.DALC
{
    public class BaseDalc
    {

        public int GetFieldAsInt(SPItem item, string fieldName)
        {
            if (item[fieldName] != null)
            {
                return Convert.ToInt32(item[fieldName]);
            }
            return 0;
        }

        public string GetFieldAsString(SPItem item, string fieldName)
        {
            if (item[fieldName] != null)
            {
                return item[fieldName].ToString();
            }
            return string.Empty;
        }

        public int GetFieldAsLookupId(SPItem item, string fieldName)
        {
            if (item[fieldName] != null)
            {
                SPFieldLookupValue value = new SPFieldLookupValue(GetFieldAsString(item, fieldName));
                return value.LookupId;

            }
            return 0;
        }

        public string GetFieldAsLookupValue(SPItem item, string fieldName)
        {
            if (item[fieldName] != null)
            {
                SPFieldLookupValue value = new SPFieldLookupValue(GetFieldAsString(item, fieldName));
                return value.LookupValue;

            }
            return null;
        }
    }
}
